<%@ page language="java" contentType="text/html; charset=UTF-8"	 pageEncoding="UTF-8"%>
<%@ include file="../include/laypublic.jsp"%>
<!DOCTYPE html>
<html>
<head>
  <title>开工审批新增</title>
</head>
<style>
	.fieldset{
		margin-top: 5px;
		margin-bottom: 0px
	}
	.layui-legend{
		background-color:#5fb878;
		font-size:15px !important;
		width:140px;
	}
	.layui-form-item {
	    margin-bottom: 5px;
	    clear: both;
	    *zoom: 1;
	}
	.layui-form-label{width: 180px;}
</style>
<body>
<div class="layui-fluid">
    <div class="layui-card">
	    <div class="layui-tab-item layui-show">
	    	<div style="padding-top:15px;">&nbsp;</div>
			<form class="layui-form" id="addInfo_form" lay-filter="add_info_from">
				<fieldset class="layui-elem-field layui-field-title fieldset"  id="baseInfo">
				  <legend class="layui-btn layui-legend" style="text-align:left;cursor:default;">项目基础信息  ></legend>
				  <div style="margin-top:20px">
				  	<div class="layui-form-item">
				  		<div class="layui-inline">
					      	<label class="layui-form-label">申请公司</label>
					      	<div class="layui-input-inline">
					      		<input type="hidden" name="hrOrgId" value="${bindOrgId}">
								<input type="text" value="${bindOrgName}" style="border: 0px;width:220px" readonly="readonly" class="layui-input">
					      	</div>
					    </div>
					    <div class="layui-inline">
					    	<label class="layui-form-label">申请部门</label>
				      		<div class="layui-input-inline">
				      			<input type="hidden" name="hrDeptId" value="${bindDeptId}">
								<input type="text" value="${bindDeptName}" style="border:0px;" readonly="readonly" class="layui-input">
				      		</div>
					    </div>
					    <div class="layui-inline">
					    	<label class="layui-form-label">申请人</label>
				      		<div class="layui-input-inline">
				        		<input type="hidden" name="hrStaffApplyId" readonly="readonly" value="${SESSION_KEY_USER_DETAIL.hrStaffId }">
				        		<input type="text" name="staffName" value="${staffName }" readonly="readonly" style="border:0px" class="layui-input">
				      		</div>
					    </div>
				    </div>
				  	<div class="layui-form-item">
				  		<div class="layui-inline">
					      	<label class="layui-form-label">项目名称</label>
					      	<div class="layui-input-inline">
					        	<select name="id" id="add_select_proId" lay-filter="add_select_proId" lay-verify="required" lay-search>
		              				<option value="">请选择-项目名称</option>
				              		<c:if test="${not empty disclosePros }">
				              			<c:forEach items="${disclosePros}" var="disclosePro">
				              				<option value="${disclosePro.id }" proCode="${disclosePro.proCode }">${disclosePro.proName }</option>
					            		</c:forEach>
				              		</c:if>
				              	</select>						        
					      	</div>
					    </div>
					    <div class="layui-inline">
					    	<label class="layui-form-label">项目地点</label>
				      		<div class="layui-input-inline">
				        		<input type="hidden" id="sgCityId" name="sgCityId">
				        		<input type="text" id="sgCityName" readonly="readonly" style="border:0px" class="layui-input">
				      		</div>
					    </div>
					    <div class="layui-inline">
					    	<label class="layui-form-label">总投资额（万元）</label>
				      		<div class="layui-input-inline">
				        		<input type="hidden" id="proCode" name="proCode">
				        		<input type="hidden" id="proName" name="proName">
				        		<input type="text" id="id_sumAmount" name="sumAmount" readonly="readonly" style="border:0px" class="layui-input">
				      		</div>
					    </div>
				    </div>				  	
		    		<div class="layui-form-item">
					    <div class="layui-inline">
					    	<label class="layui-form-label">建安工程费（万元）</label>
				      		<div class="layui-input-inline">
				        		<input type="text" id="id_costCae" name="costCae" readonly="readonly" style="border:0px" class="layui-input">
				      		</div>
					    </div>
					    <div class="layui-inline">
							<label class="layui-form-label">是否签订内部协议</label>
							<div class="layui-input-inline">
				      			<input type="hidden" id="innerSignFlag" name="innerSignFlag">
								<input type="text" id="innerSign" readonly="readonly" style="border:0px" autocomplete="off" class="layui-input">
							</div>
						</div>
						<div class="layui-inline">
					    	<label class="layui-form-label">总包单位</label>
				      		<div class="layui-input-inline">
				      			<input type="hidden" id="sgCoopId" name="sgCoopId">
				        		<input type="text" id="id_sgCoopName" name="sgCoopName" readonly="readonly" style="border:0px;width:220px" class="layui-input">
				      		</div>
					    </div>
					</div>
		    		<div class="layui-form-item">
					    <div class="layui-inline">
					    	<label class="layui-form-label">居间方</label>
				      		<div class="layui-input-inline">
				        		<input type="text" id="id_linkPower" name="linkPower" readonly="readonly" style="border:0px" class="layui-input">
				      		</div>
					    </div>
					    <div class="layui-inline">
							<label class="layui-form-label">是否签订居间方协议</label>
							<div class="layui-input-inline">
								<select name="linkSignFlag" lay-verify="required">
									<option value>请选择</option>
									<option value="1">已签订</option>
									<option value="0">未签订</option>
								</select>
							</div>
						</div>
						<div class="layui-inline">
							<label class="layui-form-label">是否确定监理单位</label>
							<div class="layui-input-inline">
								<select name="supervisorFlag" lay-verify="required">
									<option value>请选择</option>
									<option value="1">已确定</option>
									<option value="0">未确定</option>
								</select>
							</div>
						</div>
					</div>
		    		<div class="layui-form-item">
					    <div class="layui-inline">
							<label class="layui-form-label">是否确定跟踪审计单位</label>
							<div class="layui-input-inline">
								<select name="trackFlag" lay-verify="required">
									<option value>请选择</option>
									<option value="1">已确定</option>
									<option value="0">未确定</option>
								</select>
							</div>
						</div>
						<div class="layui-inline">
							<label class="layui-form-label">开工性质</label>
							<div class="layui-input-inline">
								<select name="startFlag" lay-verify="required">
									<option value>请选择</option>
									<option value="1">正式开工</option>
									<option value="0">有条件开工</option>
								</select>
							</div>
						</div>
						<div class="layui-inline">
							<label class="layui-form-label">开工子项/开工段</label>
							<div class="layui-input-inline">
								<input name="buildStage" maxlength="100" lay-verify="required" class="layui-input" />
							</div>
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">开工投入及形象要求</label>
						<div class="layui-input-block">
							<textarea name="buildMemo" class="layui-textarea" maxlength="500"
								lay-verify="required" style="width: 899px; height: 90px;"></textarea>
						</div>
					</div>
					<div class="layui-form-item">
						<div class="layui-inline">
							<label class="layui-form-label">拟开工日期</label>
							<div class="layui-input-inline">
								<input type="text" class="layui-input" id="sent-plan-start" lay-verify="required" name="planStartDate" readonly placeholder="拟开工日期">
							</div>
						</div>
						<div class="layui-inline">
							<label class="layui-form-label">拟竣工日期</label>
							<div class="layui-input-inline">
								<input type="text" class="layui-input" id="sent-plan-end" lay-verify="required" name="planEndDate" readonly placeholder="拟竣工日期">
							</div>
						</div>
					</div>
		  		</div>
			</fieldset>
			<fieldset class="layui-elem-field layui-field-title fieldset" >
		  		<legend class="layui-btn layui-legend" style="text-align:left;cursor:default;">附件信息  ></legend>
			  	<div style="margin-top:20px;">
				    <div class="layui-form-item">
					    <label class="layui-form-label" style="width:350px;">支持pdf、excel、word、图片资料，可上传多个</label>
					</div>
				    <div class="layui-form-item">
					    <label class="layui-form-label">附件资料（选填）</label>
					    <div class="layui-input-block">
					    	<div class="layui-upload">
				              	<button type="button" class="layui-btn" id="1-upload-more">上传</button>
		                		<div class="layui-upload-list" id="1-upload-more-list">
		                		</div>
				            </div>
					    </div>
				  	</div>
			  	</div>
			</fieldset>
			<fieldset class="layui-elem-field layui-field-title fieldset" >
		  		<legend class="layui-btn layui-legend" style="text-align:left;cursor:default;width:200px">十大风险排查及应对情况 ></legend>
			  	<div style="margin-top:20px;">
				    <div class="layui-form-item" style="margin: 0 20px;">
			  			<table class="layui-table layuiadmin-page-table" lay-skin="line">
		                  <thead>
		                    <tr>
		                      <th width="5%">序号</th>
		                      <th width="15%">风险类型</th>
		                      <th width="80%">进展及解决措施（选填）</th>
		                    </tr> 
		                  </thead>
		                  <tbody>
		                    <tr>
		                    	<td><input type="text" name="startBuildRisks[0].showIdx" value="1" style="border: 0px;" readonly="readonly" class="layui-input"></td>
		                    	<td><input type="text" name="startBuildRisks[0].riskName" value="入库风险" readonly="readonly" style="border:0px;" class="layui-input"></td>
		                    	<td><input type="text" name="startBuildRisks[0].riskMemo" maxlength="500" autocomplete="off" class="layui-input"></td>
		                    </tr>
		                    <tr>
		                    	<td><input type="text" name="startBuildRisks[1].showIdx" value="2" style="border: 0px;" readonly="readonly" class="layui-input"></td>
		                    	<td><input type="text" name="startBuildRisks[1].riskName" value="工程量变化风险" readonly="readonly" style="border:0px;" class="layui-input"></td>
		                    	<td><input type="text" name="startBuildRisks[1].riskMemo" maxlength="500" autocomplete="off" class="layui-input"></td>
		                    </tr>
		                    <tr>
		                    	<td><input type="text" name="startBuildRisks[2].showIdx" value="3" style="border: 0px;" readonly="readonly" class="layui-input"></td>
		                    	<td><input type="text" name="startBuildRisks[2].riskName" value="工程履约风险" readonly="readonly" style="border:0px;" class="layui-input"></td>
		                    	<td><input type="text" name="startBuildRisks[2].riskMemo" maxlength="500" autocomplete="off" class="layui-input"></td>
		                    </tr>
		                    <tr>
		                    	<td><input type="text" name="startBuildRisks[3].showIdx" value="4" style="border: 0px;" readonly="readonly" class="layui-input"></td>
		                    	<td><input type="text" name="startBuildRisks[3].riskName" value="四证齐全风险" readonly="readonly" style="border:0px;" class="layui-input"></td>
		                    	<td><input type="text" name="startBuildRisks[3].riskMemo" maxlength="500" autocomplete="off" class="layui-input"></td>
		                    </tr>
		                    <tr>
		                    	<td><input type="text" name="startBuildRisks[4].showIdx" value="5" style="border: 0px;" readonly="readonly" class="layui-input"></td>
		                    	<td><input type="text" name="startBuildRisks[4].riskName" value="融资落地和放款风险" readonly="readonly" style="border:0px;" class="layui-input"></td>
		                    	<td><input type="text" name="startBuildRisks[4].riskMemo" maxlength="500" autocomplete="off" class="layui-input"></td>
		                    </tr>
		                    <tr>
		                    	<td><input type="text" name="startBuildRisks[5].showIdx" value="6" style="border: 0px;" readonly="readonly" class="layui-input"></td>
		                    	<td><input type="text" name="startBuildRisks[5].riskName" value="融资利率倒挂风险" readonly="readonly" style="border:0px;" class="layui-input"></td>
		                    	<td><input type="text" name="startBuildRisks[5].riskMemo" maxlength="500" autocomplete="off" class="layui-input"></td>
		                    </tr>
		                    <tr>
		                    	<td><input type="text" name="startBuildRisks[6].showIdx" value="7" style="border: 0px;" readonly="readonly" class="layui-input"></td>
		                    	<td><input type="text" name="startBuildRisks[6].riskName" value="政府财政能力风险" readonly="readonly" style="border:0px;" class="layui-input"></td>
		                    	<td><input type="text" name="startBuildRisks[6].riskMemo" maxlength="500" autocomplete="off" class="layui-input"></td>
		                    </tr>
		                    <tr>
		                    	<td><input type="text" name="startBuildRisks[7].showIdx" value="8" style="border: 0px;" readonly="readonly" class="layui-input"></td>
		                    	<td><input type="text" name="startBuildRisks[7].riskName" value="政府原因造成签证变更落地风险" readonly="readonly" style="border:0px;" class="layui-input"></td>
		                    	<td><input type="text" name="startBuildRisks[7].riskMemo" maxlength="500" autocomplete="off" class="layui-input"></td>
		                    </tr>
		                    <tr>
		                    	<td><input type="text" name="startBuildRisks[8].showIdx" value="9" style="border: 0px;" readonly="readonly" class="layui-input"></td>
		                    	<td><input type="text" name="startBuildRisks[8].riskName" value="后期运维风险" readonly="readonly" style="border:0px;" class="layui-input"></td>
		                    	<td><input type="text" name="startBuildRisks[8].riskMemo" maxlength="500" autocomplete="off" class="layui-input"></td>
		                    </tr>
		                    <tr>
		                    	<td><input type="text" name="startBuildRisks[9].showIdx" value="10" style="border: 0px;" readonly="readonly" class="layui-input"></td>
		                    	<td><input type="text" name="startBuildRisks[9].riskName" value="超概风险" readonly="readonly" style="border:0px;" class="layui-input"></td>
		                    	<td><input type="text" name="startBuildRisks[9].riskMemo" maxlength="500" autocomplete="off" class="layui-input"></td>
		                    </tr>
		                  </tbody>
		                </table>
				    </div>
			  	</div>
			</fieldset>
			<div class="layui-form-item" style="position: fixed ! important; right: 30px; bottom:45%;z-index:10000;">
				<div class="layui-input-block">
		      		<button class="layui-btn layui-bg-blue layui-btn-normal layui-btn-lg  layui-btn-radius" type="button" lay-submit lay-filter="addInfo_form_submit" id="addInfo_form_submit">
		      		<i class="layui-icon layui-icon-ok layuiadmin-button-btn"></i>
		      		提交
		      		</button>
		      	</div>
		    </div>
		</form>
  		</div>
	</div>
</div>
  <script>
	//静态资源路径前缀
	var staticPath = '${fileHttpPre}';
	var stateJSON = <infopub:dicJson groupNo="A00010028" />;
	
  layui.config({
    base: '${ctx}/resources/layuiadmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'set', 'upload', 'element', 'laydate'], function(){
    var $ = layui.$
    ,form = layui.form
    ,element = layui.element
    ,laydate = layui.laydate
    ,upload = layui.upload;
    
    //拟开工日期开始日期
   	var psStart = laydate.render({
      elem: '#sent-plan-start'
      ,done: function(value, date){
        //更新结束日期的最小日期
        psEnd.config.min = lay.extend({}, date, {
          month: date.month - 1
        });
        
        //自动弹出结束日期的选择器
       psEnd.config.elem[0].focus();
      }
    });
    
    //拟开工日期结束日期
    var psEnd = laydate.render({
      elem: '#sent-plan-end'
      ,done: function(value, date){
        //更新开始日期的最大日期
        psStart.config.max = lay.extend({}, date, {
          month: date.month - 1
        });
      }
    });
 	// 正则校验
	form.verify({
		//验证汉字
	    CHS:[
	    	/^[\u0391-\uFFE5]+$/
	    	,'只能输入汉字'
	  	],
	  	//大于0的正整数
	  	intNumber:[
			/^[1-9]\d*$/
			,'请输入正确的数字'
	  	],
	  	//数字只能有两位小数
	  	floatNumber:[
			/^([-]?)([0-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/
			,'请输入正确的数字'
	  	],
	  	//数字大于等于0，并只能有两位小数
	  	floatAmount:[
			/^([0-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/
			//var pattern=/^((\d+\.\d*[1-9]\d{1})|(\d*[1-9]\d*\.\d{2}))$/; 
			,'请输入正确的数字'
	  	]
	});
 	
	//附件资料
  	upload.render({
	      elem: '#1-upload-more'
	      ,url: basePath + '/startBuild/uploadAtt/'
	      ,multiple: true
	      ,accept: 'file'
	      ,acceptMime: 'application/zip,application/x-rar-compressed,image/jpeg,image/png,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.ms-powerpoint,application/vnd.openxmlformats-officedocument.presentationml.presentation,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/pdf'
	   	  ,before: function(obj){ //obj参数包含的信息
	   		    layer.load(); //上传loading
	   		  }
	      ,done: function(res){
	    	  //如果上传失败
	          if(res.code > 0){
	        	  layer.closeAll('loading'); //关闭loading
	        	  return layer.msg(res.msg,{icon: 7});
	          }
	          //上传完毕
	   	  	  if(res.entity != null && res.entity.length > 0){
				for(var i in res.entity){
					var startBuild = res.entity[i];
					var arr = startBuild.split("|");
					var imgSrc = "";
					var suffix = arr[0].substring(arr[0].lastIndexOf(".")+1,arr[0].length);
					if(suffix == 'jpg' || suffix == 'png'){
						imgSrc = "${fileHttpPre}/"+arr[2];
					}else{
						imgSrc = "${ctx}/resources/images/"+suffix+".jpg";
					}
	        		$('#1-upload-more-list').append('<div class="layui-upload-img-div" id="upload_img_'+arr[1]+'"><img src="'+imgSrc+'" title="'+ arr[0] +'" class="layui-upload-img"><div class="mask"><a href="javascript:void(0)" onclick="showImg(\''+"${fileHttpPre}"+arr[2] +'\');">查看</a><a href="javascript:void(0)" onclick="del(\''+arr[1]+'\')";>删除</a></div><p>'+arr[0]+'</p><input type="hidden" value="'+startBuild+'" id="fileAtt_'+arr[1]+'" name="fileAtt" ></input></div> ');
				}
		  	  }
	      }
	      ,allDone: function(obj){ //当文件全部被提交后，才触发
	    	  layer.closeAll('loading'); //关闭loading
	      }
	      ,error: function(){
	    	  layer.closeAll('loading'); //关闭loading
	          //上传失败
	          layer.msg("上传失败，请稍后再试~",{icon: 7});
	        }
	    });
	
  	//项目名称select监听
    form.on('select(add_select_proId)', function(data){
    	var proId = data.value;
		if (proId == '' || proId == null) {
			layer.msg('请选择项目名称', {
				icon : 1
			});
			return;
		}
		var proName = $("#add_select_proId").find("option:selected").text().trim();
		$("#proName").val(proName);
		var proCode = $("#add_select_proId").find("option:selected").attr("proCode");
		$("#proCode").val(proCode);
    	//通过项目名称带出所需要的的数据
		$.ajax({
			type : "POST", //提交方式  
			url : "${ctx}/startBuild/getDiscloseProById",//路径  
			data : {
				"id" :proId
			},//数据，这里使用的是Json格式进行传输  
			success : function(result) {//返回数据根据结果进行相应的处理 
				if(result.flag==true){
					if(result.disclosePro!=null){						
						if(result.disclosePro.costCae!=null&&result.disclosePro.costCae!=''){
							$("#id_costCae").val(result.disclosePro.costCae);
							$("#id_sumAmount").val(result.disclosePro.sumAmount);
							$("#sgCityId").val(result.disclosePro.sgCityId);
							$("#sgCityName").val(result.disclosePro.sgCityName);
							$("#id_linkPower").val(result.disclosePro.linkPower);
						}else{
							$("#id_costCae").val(0);
							$("#id_sumAmount").val(0);
						}
						form.render();
					}else{
						layer.msg('未查到交底记录信息~',{icon: 0});
					}
				}				
			} 
		});
    	//根据项目编号查询内部协议信息
		$.ajax({
			type : "POST", //提交方式  
			url : "${ctx}/startBuild/getInnerAgrtByProCode",//路径  
			data : {
				"proCode" :proCode
			},//数据，这里使用的是Json格式进行传输  
			success : function(result) {//返回数据根据结果进行相应的处理 
				if(result.flag==true){
					if(result.innerAgrt != null && result.innerAgrt!= ''){
						$("#innerSignFlag").val('1');
						$("#innerSign").val('已签订');
						if(result.coopInfo!=null){
							$("#sgCoopId").val(result.innerAgrt.sgCoopId);
							$("#id_sgCoopName").val(result.coopInfo.coopName);
						}else{
							$("#sgCoopId").val('');
							$("#id_sgCoopName").val('');
						}
					}else{
						$("#innerSignFlag").val('0');
						$("#innerSign").val('未签订');
						$("#sgCoopId").val('');
						$("#id_sgCoopName").val('');
					}
				}else{
					$("#innerSignFlag").val('0');
					$("#innerSign").val('未签订');
					$("#sgCoopId").val('');
					$("#id_sgCoopName").val('');
					layer.msg('未查到内部协议记录信息~',{icon: 0});
				}
			} 
		});
	});
   	//监听提交
  	form.on('submit(addInfo_form_submit)', function(data){ 
  		$("#addInfo_form_submit").removeAttr("lay-submit").removeClass("layui-bg-blue").addClass("layui-btn-disabled");
  		layer.load();
       	//提交 Ajax 成功后，静态更新表格中的数据
       	$.ajax({
           	type : 'post',
			url : basePath + '/startBuild/save',
           	data: $('#addInfo_form').serialize(),
			success:function(result){
				if(result.success){
					layer.closeAll('loading'); //关闭loading
					layer.msg('提交单据成功~',{icon: 1});
					//两秒后关闭当前页面
					setTimeout(function(){
						/**
						 * 查找父菜单，并刷新
						 */
						var topDoc = $(window.top.document);
						var path = basePath + '/startBuild/list';
						// 获取页面名称
						var name = topDoc.find(".layui-nav-item [lay-href^='" + path + "']").text();
						if(name == '' || name == null){
							name = '开工审批';
						}
						window.parent.layui.index.openTabsPage(path, name);
						var iframe = window.parent.layui.admin.tabsBody(window.parent.layui.admin.tabsPage.index).find(".layadmin-iframe");
						iframe[0].contentWindow.location.reload(true);
						
						/**
						 * 关闭当前页
						 */
						var currPath = basePath + '/startBuild/add';
						var layid = topDoc.find("li[lay-id^='" + currPath + "']").attr('lay-id');
						window.parent.layui.element.tabDelete('layadmin-layout-tabs', layid);//关闭当前页
				        }, 2000);
				}else{
					layer.closeAll('loading'); //关闭loading
  					$("#addInfo_form_submit").removeClass("layui-btn-disabled").addClass("layui-bg-blue").attr("lay-submit","");
					layer.msg(result.msg,{icon: 7});
			  	}
			}
       	});
   	});  
 	// data-type事件
    $('.layui-btn.layuiadmin-btn-admin').on('click', function(){
      var type = $(this).data('type');
      active[type] ? active[type].call(this) : '';
    });
  	
  });
	
	//删除文件
	function del(index){
		layui.$("#fileAtt_"+index).remove();
		layui.$("#upload_img_"+index).remove();
	}
  
	//根据url查看文件
	function showImg(url){
		var openWin = window.open(url,'','left=410,height=768, width=1024, top=200,  toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no');
	}
	
  </script>
</body>
</html>

